package com.base.controller.utils;

import com.alibaba.fastjson.JSONObject;
import com.base.Filter.sign.SignUtil;
import com.base.po.voip.Callbackinfoes;
import com.base.utils.DateUtil;
import com.google.common.collect.Maps;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

public class qskUtils {
    public static void main(String[] args) {
        Callbackinfoes callbackinfoes = new Callbackinfoes();
        callbackinfoes.setId("1231231");
        callbackinfoes.setCalle164("18055603791");
        callbackinfoes.setCaller("18557542013");
        callbackinfoes.setMoney(new BigDecimal(0));
        callbackinfoes.setCalltime(new Date());
        callbackinfoes.setTimecount(12);
        callbackinfoes.setParentid("wdawda");
        callbackinfoes.setSysnum("21212");
        callbackinfoes.setFwdtime(new Date());
        callbackinfoes.setEndtime(new Date());
        String str = getCallBackURL(callbackinfoes);
        System.out.println(str);


    }

    /**
     *
     * @param callbackinfoes
     * @return 骑士卡专享
     */
    public static String getCallBackURL(Callbackinfoes callbackinfoes) {
        SortedMap<Object, Object> maps = new TreeMap<>();
        maps.put("appkey", "qishika");
        maps.put("timestamp", System.currentTimeMillis());
        maps.put("id", callbackinfoes.getId());
        maps.put("caller", callbackinfoes.getCaller());
        maps.put("calle164", callbackinfoes.getCalle164());
        maps.put("calltime", DateUtil.dateToStrLong(callbackinfoes.getCalltime()));
        maps.put("timecount", callbackinfoes.getTimecount());
//        maps.put("status",callbackinfoes.getStatus());
        maps.put("parentid", callbackinfoes.getParentid());
        maps.put("sysnum", callbackinfoes.getSysnum());
        maps.put("fwdtime", DateUtil.dateToStrLong(callbackinfoes.getFwdtime()));
        maps.put("endtime", DateUtil.dateToStrLong(callbackinfoes.getEndtime()));
        maps.put("money", callbackinfoes.getMoney());
        String appsecret = "7F499C134731050CC1E9671C2289B458";
        String sign = SignUtil.getSign("utf-8", maps, appsecret);
        maps.put("sign", sign);
        Map<String,Object> map= Maps.newHashMap();
        maps.forEach((k,v)->{
            map.put(k.toString(),v);
        });
        JSONObject paramsObj = new JSONObject(map);
//        JSONObject json = JSONObject.parseObject(map);
        System.out.println(paramsObj.toJSONString());
        String str=paramsObj.toJSONString();
//        String str= qskUtils.getCallBackURL(callbackinfoes);
        net.sf.json.JSONObject jsonObject1= net.sf.json.JSONObject.fromObject(str);
//        WebHelper.doBodyPost("http://localhost:8080/SbdVoip/callTest/getCallBack",jsonObject1);

        return paramsObj.toJSONString();
    }
}
